package model

import (
	"time"
)

// User 用户表
type Sapplys struct {
	Id        int       `json:"id" form:"id"`
	Sno       string    `json:"sno" form:"sno"`
	Sname     string    `json:"sname" form:"sname"`
	Type      string    `json:"type" form:"type"`
	Content   string    `json:"content" form:"content"`
	Count     int       `json:"count" form:"count"`
	Date      time.Time `json:"date" form:"date"`
	Cid       string    `json:"cid" form:"cid"`
	Sex       int       `json:"sex" form:"sex"`
	Call      string    `json:"call" form:"call"`
	Infocunt  int       `json:"infocunt" form:"infocunt"`
	Bukao     int       `json:"bukao" form:"bukao"`
	Score_asc int       `json:"score_asc" form:"score_asc"`
}

func SapplysAll(cid string) ([]Sapplys, error) {
	mods := make([]Sapplys, 0, 4)
	err := DB.Select(&mods, "select * from sapply where cid=?", cid)
	return mods, err
}

func SapplyAdd(sno, sname, type1, content, sex, call string, infocunt, bukao, score_asc, cid int) bool {

	result, _ := DB.Exec("INSERT INTO `sapply` (`date`,`sno`, `sname`, `type`, `content`, `sex`, `call`, `infocunt`, `bukao`, `score_asc`,`cid`) VALUES(?,?,?,?,?,?,?,?,?,?,?)", time.Now().Format("2006-01-02"), sno, sname, type1, content, sex, call, infocunt, bukao, score_asc, cid)

	affect, _ := result.RowsAffected()
	if affect == 1 {
		return true
	}
	return false

}
